package goods

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"weekly-exam-1/config"
	"weekly-exam-1/internal/model/dao"
)

type List struct {
	Bank     int `form:"bank" json:"bank" xml:"bank" `
	BigSmall int `form:"bigSmall" json:"bigSmall" xml:"bigSmall" `
	Looks    int `form:"looks" json:"looks" xml:"looks"`
}

func GoodList(c *gin.Context) {
	var json List
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	var goods []dao.Goods
	config.DB.Where("bank=? or big_small=? or looks=?", json.Bank, json.BigSmall, json.Looks).Find(&goods)

	var list []*dao.Goods
	for _, good := range goods {
		if good.Status == 0 {
			list = append(list, &dao.Goods{
				UserId:   good.UserId,
				Bank:     good.Bank,
				BigSmall: good.BigSmall,
				BuyType:  good.BuyType,
				Looks:    good.Looks,
				Price:    good.Price,
				Status:   good.Status,
			})
		}
	}
	c.JSON(http.StatusOK, gin.H{
		"msg":  "查找成功",
		"data": list,
	})
	//for _, d := range list {
	//	if d.Status == 0 {
	//
	//	}
	//}

}
